package cuiyt.juc.bq.linkedblockingqueue;

import cn.hutool.core.collection.SpliteratorUtil;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author cyt
 * @describe
 * @create 2020-12-21 19:33
 */
public class LinkedBlockingQueueTest {
    public static void main(String[] args) throws InterruptedException {
        testAtomicInteger();

        LinkedBlockingQueue<Integer> linkedQueue = new LinkedBlockingQueue<>(3);

        linkedQueue.add(34);
        linkedQueue.add(3);
        linkedQueue.put(3);
        System.out.println(linkedQueue.take());

        System.out.println(linkedQueue.peek());
        System.out.println(linkedQueue.poll());
        System.out.println(linkedQueue.poll());
        System.out.println(linkedQueue.poll());
        System.out.println(linkedQueue.remove());
        linkedQueue.put(4);
        System.out.println(linkedQueue.size());
    }

    private static void testAtomicInteger() {
        AtomicInteger integer = new AtomicInteger();
        int i = integer.get();
        System.out.println("get: " + i);
        int andIncrement = integer.getAndIncrement();
        System.out.println("getAndIncrement： " + andIncrement);
        i = integer.get();
        System.out.println("get: " + i);
    }
}
